package com.dd;

import com.dd.exception.UnauthorizedException;
import com.dd.exception.UserNotFoundException;

/**
 * 系统运行后一些环境参数设置和临时变量存储
 * 当前登陆用户信息初始化
 * @author sgw
 *
 */
public class SysEnvironmentInit {


	private User pageUser;

	
	public User getPageUser() {
		return pageUser;
	}

	/**
	 * 登陆用户信息初始化
	 * @param authToken
	 * @throws Exception
	 */
	public void registeUserInit(Authorization authToken) throws Exception {
		UserManager um = new UserManager(); 
		this.pageUser =um.getUser(authToken.getUserID());
	}


	/**
	 * 取得用户信息
	 * @param userID
	 * @return
	 */
	public User getUser(int userID) {
		UserManager um = new UserManager();
		User user = null;
		try {
			user = um.getUser(userID);
			return user;
		} catch (UserNotFoundException unfe) {
			return null;
		}
	}

	/**
	 * 取得当前用户的权限
	 * @param userID
	 * @return
	 * @throws UnauthorizedException
	 */
	public Permissions getUserPermissions(int userID)
			throws UnauthorizedException {
		PermissionsManager permissionsManager = new PermissionsManager();
		return permissionsManager.getPermissions(userID);
	}


}
